package com.decorate.maindata.controller;

import #(packageBase).data.#(className)Data;
import #(packageBase).data.#(className)QueryData;
import #(packageBase).model.#(className);
import #(packageBase).service.#(className)Service;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @Description
* @Created by yufeng
*/
@RestController
@RequestMapping("/#(classNameSmall)")
public class #(className)Controller {
    @Autowired
    #(className)Service #(classNameSmall)Service;

    /**
    * 保存
    *
    * @param #(classNameSmall)
    * @date: 14:51 2019/10/17
    **/
    @PostMapping("/save")
    public #(className)Data #(classNameSmall)SaveOrUpdate(@RequestBody #(className) #(classNameSmall)) {
        Integer row;
        if (null == #(classNameSmall).getId()) {
        row = #(classNameSmall)Service.insertSelective(#(classNameSmall));
        } else {
        row = #(classNameSmall)Service.updateByPrimaryKeySelective(#(classNameSmall));
        }
        if (row == 0) {
        return null;
        }
        #(className)Data #(classNameSmall)Data = new #(className)Data();
        BeanUtils.copyProperties(#(classNameSmall), #(classNameSmall)Data);
        return #(classNameSmall)Data;
    }

    /**
    * 根据ID删除
    *
    * @param id
    * @date: 14:51 2019/10/17
    * @return: java.lang.Integer
    **/
    @PostMapping("/delete")
    public Integer #(classNameSmall)Delete(@RequestParam(value = "id") Long id) {

        return #(classNameSmall)Service.deleteByPrimaryKey(id);
    }

    /**
    * 分页搜索查询
    *
    * @param #(classNameSmall)QueryData
    * @date: 14:51 2019/10/17
    **/
    @PostMapping("/list/page")
    public PageInfo<#(className)Data> #(classNameSmall)ListPage(@RequestBody #(className)QueryData #(classNameSmall)QueryData) throws Exception {
        return #(classNameSmall)Service.selectListPage(#(classNameSmall)QueryData);
        }


        /**
        * 根据ID查询户型
        * @param id
        * @date: 14:52 2019/10/17
        **/
        @PostMapping("/get")
        public #(className)Data #(classNameSmall)GetOne(@RequestParam("id") Long id) {
            #(className) #(classNameSmall) = #(classNameSmall)Service.selectByPrimaryKey(id);
            if (null != #(classNameSmall)) {
            #(className)Data #(classNameSmall)Data = new #(className)Data();
             BeanUtils.copyProperties(#(classNameSmall), #(classNameSmall)Data);
             return #(classNameSmall)Data;
            }
            return null;
        }
 }
